package com.engine.core.domain;

import com.alibaba.fastjson.JSONArray;

import java.util.List;

public class JavaFunction {
    private String expression;
    private List<String> params;
    private String column;

    private Integer orderBy;

    private Object computedValue;

    /**
     * 0:输出
     * 1:输入
     */
    private int type;

    public JavaFunction(String expression, List<String> params, String column) {
        this.expression = expression;
        this.params = params;
        this.column = column;
    }

    /**
     * 0:输出
     * 1:输入
     */
    public JavaFunction(String expression, String column,int type) {
        this.expression = expression;
        this.column = column;
        this.type = type;
    }

    public void setArgs(JSONArray args){
        for (int i = 0; i < args.size(); i++) {
            String arg=args.getString(i);
            if(arg.contains(":")){
                params.add("'"+arg+"'");
            }else{
                params.add(arg);
            }
        }
    }

    @Override
    public String toString() {
        return expression;
    }

    public String getExpression() {
        return expression;
    }

    public void setExpression(String expression) {
        this.expression = expression;
    }

    public List<String> getParams() {
        return params;
    }

    public void setParams(List<String> params) {
        this.params = params;
    }

    public String getColumn() {
        return column;
    }

    public void setColumn(String column) {
        this.column = column;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Object getComputedValue() {
        return computedValue;
    }

    public void setComputedValue(Object computedValue) {
        this.computedValue = computedValue;
    }

    public Integer getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(int orderBy) {
        this.orderBy = orderBy;
    }
}
